<?php
require_once 'config.php'; 
require_once 'Tools.class.php'; 
require_once 'HTML.class.php'; 
class News{
    private $line1="-----------------\n";
    private $line2="===============\n";
	
    //获取新闻列表
    function getNewsList($openid){
        //@NEW
        #title:山东省委党校管理学教研部戚汝庆主任一行来校交流考察
        #id:1697
        #date:2014-09-28 09:08:22
        #class:学院新闻
        #view:2
        #author:新闻中心
        $code = Tools::getHttp(API_URL."newslist.php");
        $code = trim($code);
        $cjb = explode("@NEW",$code);
        $strTitle = "【学院新闻】\n".$this->line2;
        for($i=1;count($cjb)>$i;$i++){
            $title = Tools::getInfo($cjb[$i],"title");
            $id = Tools::getInfo($cjb[$i],"id");
            $date = Tools::getInfo($cjb[$i],"date");
            $class = Tools::getInfo($cjb[$i],"class");
            $view = Tools::getInfo($cjb[$i],"view");
            $author = Tools::getInfo($cjb[$i],"author");
            $str .= "★<a href=\"".API_URL."newsshow.php?id=".$id."\">".$title."</a>";
            $str .= "(".substr($date, 5,5).")";
            $str .= "\n".$this->line1;
        }
        //$str = $strTitle.substr($str,0,-(strlen($this->line1)));
        $str = $strTitle.$str."<a href=\"".API_URL."weixin/web/index.php?action=news&opid=_OPID\">点击查看更多</a>";
        return $str;
    }

    function getWebNewsList($p,$opid){
        $p = max(1, (int)$p);
        $code = Tools::getHttp(API_URL."newslist.php?p=".$p);
        $code = trim($code);
        $cjb = explode("@NEW",$code);
        for($i=1;count($cjb)>$i;$i++){
            $title = Tools::getInfo($cjb[$i],"title");
            $id = Tools::getInfo($cjb[$i],"id");
            $date = Tools::getInfo($cjb[$i],"date");
            $class = Tools::getInfo($cjb[$i],"class");
            $view = Tools::getInfo($cjb[$i],"view");
            $author = Tools::getInfo($cjb[$i],"author");

            $str .= HTML::makeList2("news.png",$title,"时间:".substr($date, 5,5).' 浏览:'.$view,API_URL."newsshow.php?id=".$id);
        }
        
        if($str==''){
            $str=HTML::makeListNULL("暂无新闻");
        }else{
            $str.=HTML::makeFooterButton(API_URL."weixin/web/index.php?action=news&opid=".$opid."&p=".($p+1),"下一页");
        }
        $tpl=file_get_contents(API_URL."weixin/web/list.html");
        $tpl=str_replace("_FORM", "", $tpl);
        $tpl=str_replace("_TITLE", '学院新闻', $tpl);
        $tpl=str_replace("_LIST", $str, $tpl);
        return $tpl;
    }


}
?>